/*!
 * @file gfxDebug.cpp
 * @brief Ciało gfxDebug.hh
 */

#include "engine/gfx/gfxDebug.hh"
using namespace std;

/*--------------------------------------------------------------------------*/

gfxDebug::gfxDebug() {
	/*
	 * Osie
	 */
	this->isAxisVisible = &pawirr::set->put("debug_axis", 1)->i;

	this->GLList_Axis = glGenLists(1);

	glNewList(this->GLList_Axis, GL_COMPILE);
	glBegin(GL_LINES);
	glColor3f(1.0f, 0.0f, 0.0f);
	glVertex3f(-100000.0f, 0.0f, 0.0f);
	glVertex3f(100000.0f, 0.0f, 0.0f);

	glColor3f(0.0f, 1.0f, 0.0f);
	glVertex3f(0.0f, 100000.0f, 0.0f);
	glVertex3f(0.0f, -100000.0f, 0.0f);

	glColor3f(0.0f, 0.0f, 1.0f);
	glVertex3f(0.0f, 0.0f, 100000.0f);
	glVertex3f(0.0f, 0.0f, -100000.0f);
	glEnd();
	glEndList();

	/*
	 * Licznik FPS
	 */
	this->FPSTestBegin = 0;
	this->FPSResult = 0;

	pawirr::set->put("debug_fps", 1);
	this->isFPSVisible = &pawirr::set->get("debug_fps")->i;
}

/*--------------------------------------------------------------------------*/

void gfxDebug::render2d() {

	if (*this->isFPSVisible != 0) {

		if (this->FPSTestBegin == 0) {
			this->FPSTestBegin = pawirr::getTime();
		} else if (this->FPSTestBegin + 1000 < pawirr::getTime()) {
			this->FPSResult = this->FPSCounter;
			this->FPSCounter = 0;
			this->FPSTestBegin = pawirr::getTime();
		} else {
			this->FPSCounter++;
		}

		stringstream ss;
		ss << "FPS " << this->FPSResult;

		pawirr::temp->fontDefault->renderToScreen(point2f(20, 20), color_yellow, ss.str());
	}

}

/*--------------------------------------------------------------------------*/

void gfxDebug::render3d() {

	if (*this->isAxisVisible != 0) {
		glCallList(this->GLList_Axis);
	}

}

/*--------------------------------------------------------------------------*/
